package tfts

func (f *Fight) DoubleCast(rate int) *Fight {
	f.stat().castAmp = rate
	return f
}

func (f *Fight) TripleCast(rate int) *Fight {
	f.stat().castAmp = rate
	return f
}

func (f *Fight) ap() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().ap * attr.stat().factor / 100
		}
	}
	return float64(num) / 100
}

func (f *Fight) as() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().as * attr.stat().factor / 100
		}
	}
	// 攻速上限为5.0
	if float64(num)*f.speed/100 > 5.0 {
		return 5.000 / f.speed
	}
	return float64(num) / 100
}

func (f *Fight) strike() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().strike
		}
	}
	return float64(num) / 100
}

func (f *Fight) castAmp() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().castAmp * attr.stat().factor / 100
		}
	}
	return float64(num) / 100
}

func (f *Fight) hitMana() int {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().hitMana * attr.stat().factor / 100
		}
	}
	return num
}

func (f *Fight) manaAmp() float64 {
	num := 1.0
	for _, attr := range f.attrs {
		if attr.valid() && attr.stat().manaAmp > 0 {
			num *= float64(attr.stat().manaAmp*attr.stat().factor/100) / 100
		}
	}
	return num
}

func (f *Fight) manaShrink() float64 {
	num := 1.00
	for _, attr := range f.attrs {
		if attr.valid() {
			shrink := float64(100 - attr.stat().manaShrink*attr.stat().factor/100)
			num *= shrink / 100
		}
	}
	return num
}

func (f *Fight) manaDec() int {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().manaDec * attr.stat().factor / 100
		}
	}
	return num
}

func (f *Fight) hp() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().health * attr.stat().factor / 100
		}
	}
	return float64(num)
}

func (f *Fight) ar() int {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().armor * attr.stat().factor / 100
		}
	}
	if f.Shred {
		// 默认被减甲
		return num * 7 / 10
	}
	return num
}

func (f *Fight) mitigate() float64 {
	return 100 / float64(100+f.ar()) * f.taken()
}

func (f *Fight) taken() float64 {
	num := 1.0
	for _, attr := range f.attrs {
		if attr.valid() && attr.stat().dmgTaken > 0 {
			num *= float64(attr.stat().dmgTaken*attr.stat().factor) / 100 / 100
		}
	}
	return num
}

func (f *Fight) hpAmp() float64 {
	num := 0.0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += float64(attr.stat().healthAmp*attr.stat().factor/100) / 100
		}
	}
	return num
}

func (f *Fight) rcvAmp() float64 {
	num := 0.0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += float64(attr.stat().recoverAmp*attr.stat().factor/100) / 100
		}
	}
	return num
}

func (f *Fight) shdAmp() float64 {
	num := 0.0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += float64(attr.stat().shieldAmp*attr.stat().factor/100) / 100
		}
	}
	return num
}

func (f *Fight) hlAmp() float64 {
	num := 0.0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += float64(attr.stat().healAmp*attr.stat().factor/100) / 100
		}
	}
	return num
}

func (f *Fight) hit() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().hitRecover * attr.stat().factor / 100
		}
	}
	return float64(num)
}
